package com.kude.service;

import java.util.List;

import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.kude.entity.Administrator;
import com.kude.entity.ArticleCategoryPrefix;
import com.kude.manager.ArticleCategoryPrefixManager;
import com.kude.manager.OperException;
import com.kude.util.BeanFactory;

public class ArticleCategoryPrefixService {

	private static final Logger logger = LoggerFactory
			.getLogger(ArticleCategoryPrefixService.class.getName());

	private ArticleCategoryPrefixManager articleCategoryPrefixManager;

	/**
	 * 获取指定ID的类别前缀
	 * @param id
	 * @return
	 * @throws OperException
	 */
	public ArticleCategoryPrefix getArticleCategoryPrefix(int id) throws OperException{
		return articleCategoryPrefixManager.get(id);
	}
	
	/**
	 * 增加文章类别前缀
	 * @param articleCategoryPrefix
	 * @return
	 * @throws OperException
	 */
	public boolean addArticleCategoryPrefix(ArticleCategoryPrefix articleCategoryPrefix) throws OperException{
		 // TODO 保证prefix的唯一
		articleCategoryPrefixManager.add(articleCategoryPrefix);
			return true;
		
	}
	/**
	 * 更新首级文章类别的属性
	 * 
	 * @param articleCategoryPrefix
	 * @throws OperException
	 */
	public void updateArticleCategoryPrefix(ArticleCategoryPrefix articleCategoryPrefix) throws OperException {
		articleCategoryPrefixManager.update(articleCategoryPrefix);
	}
	
	/**
	 * 删除首级文章类别
	 * @param id
	 * @throws OperException
	 */
	public void deleteArticleCategoryPrefix(int id) throws OperException{
		//TODO 外键限制，先提示清空所属类别后再进行删除
		articleCategoryPrefixManager.delete(id);
	}
	
	public List findAll() throws OperException {
		System.out.println(articleCategoryPrefixManager+"222222222222222");
		return articleCategoryPrefixManager.find(Restrictions.isNotNull("prefixId"));
	}
	
	public List findByPrefixName(Object prefixName) throws OperException {
		return articleCategoryPrefixManager.find(Restrictions.like("articleProfixName", prefixName+"%",MatchMode.ANYWHERE));
	}

	public void setArticleCategoryPrefixManager(
			ArticleCategoryPrefixManager articleCategoryPrefixManager) {
		this.articleCategoryPrefixManager = articleCategoryPrefixManager;
	}



	


}
